<template>
  <div class="app-container">
    <el-form :inline="true" ref="ruleForm"  :model="formInline" class="demo-form-inline">
       <el-form-item label="账号" prop="account">
        <el-input v-model="formInline.account" placeholder="请输入账号" @keyup.enter.native="toSearch"></el-input>
      </el-form-item>
       <el-form-item label="昵称" prop="nick">
        <el-input v-model="formInline.nick" placeholder="请输入昵称" @keyup.enter.native="toSearch"></el-input>
      </el-form-item>
       <el-form-item label="会员类型" prop="target_type">
        <el-select v-model="formInline.target_type" placeholder="会员类型">
          <el-option
            v-for="item in typeList"
            :label="item.title"
            :key="item.value"
            :value="item.value"

          ></el-option>
        </el-select>
      </el-form-item>
       <el-form-item label="举报类别" prop="cate">
        <el-select v-model="formInline.cate" placeholder="举报类别">
          <el-option
            v-for="item in cateList"
            :label="item.name"
            :key="item.value"
            :value="item.name"

          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="赛事房间" prop="room">
        <el-input v-model="formInline.room" placeholder="请输入赛事房间" @keyup.enter.native="toSearch"></el-input>
      </el-form-item>
      <el-form-item label="举报人数" prop="num">
        <el-form-item class="with-pre-select" >
          <el-input placeholder="请输入次数" v-model="formInline.num" class="input-with-select" @keyup.enter.native="toSearch">
            <el-select v-model="formInline.numType" slot="prepend" placeholder="全部">
              <el-option label="全部" value="0"></el-option>
              <el-option label="举报次数≥" value="1"></el-option>
              <el-option label="举报次数<" value="2"></el-option>
            </el-select>
          </el-input>
      </el-form-item>

      </el-form-item>

      <el-form-item label="用户状态" prop="status">
        <el-select v-model="formInline.status" placeholder="用户状态">
          <el-option
            v-for="item in userStatus"
            :label="item.title"
            :key="item.value"
            :value="item.value"

          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-col>
          <el-form-item prop="time" label="发送时间">
            <el-date-picker
              v-model="formInline.time"
              type="datetimerange"
              align="right"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd HH:mm:ss"
              :default-time="['00:00:00', '23:59:59']"
              :picker-options="pickerWeekStep">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="toSearch">搜索
      </el-button>
      <el-button @click="selfResetForm('ruleForm')">重置</el-button>
    </el-form>
  </div>

</template>
<script>
import { form, grid, pickerOption } from '@/build';
import { getcate, getBannedTime } from '@/services/api/chatRoom';


export default {
  name: 'form-filter',
  mixins: [form, grid, pickerOption],
  data() {
    return {

      cateList: [],
      userStatus: [
        { title: '全部', value: '' },
        { title: '正常', value: '0' },
        { title: '禁言中', value: '1' },
      ],
      typeList: [
        { title: '全部', value: '' },
        { title: '本站会员', value: '0' },
        { title: '外部拉取', value: '1' },
      ],
      formInline: {
        time: [
          moment().format('YYYY-MM-DD 00:00:00'),
          moment().format('YYYY-MM-DD 23:59:59'),
        ],
        account: '', // 账号
        nick: '', // 昵称
        cate: '',
        room: '',
        num_min: '',
        num_max: '',
        status: undefined,
        numType: '',
        num: null,
        target_type: undefined, // 0 本站会员 1外部拉取
        page: 1,
        size: 20,
      },
    };
  },
  methods: {
    toSearch() {
      const reg = /^[1-9]\d*$/;
      if (this.formInline.numType != '0' && this.formInline.num) {
        const reg = /^[1-9]\d*$/;
        if (!reg.test(this.formInline.num)) {
          this.$message({
            message: '举报次数格式不正确',
            type: 'error',
          });
          return;
        }
      }
      if (this.formInline.numType == '0') {
        this.formInline.num_min = undefined;
        this.formInline.num_max = undefined;
      } else if (this.formInline.numType == '1') {
        this.formInline.num_min = this.formInline.num;
        this.formInline.num_max = undefined;
      } else if (this.formInline.numType == '2') {
        this.formInline.num_min = undefined;
        this.formInline.num_max = this.formInline.num;
      }
      this.$emit('on-filter', this.formInline);
    },
    selfResetForm(formName) {
      this.formInline.numType = '0';
      this.formInline.num = null;
      this.formInline.num_min = undefined;
      this.formInline.num_max = undefined;
      this.formInline.status = undefined;
      this.resetForm(formName);
      this.$emit('on-filter', this.formInline);
    },
  },
  mounted() {
    this.bindGet(getcate, 'cateList', {
      sendingData: {},
      format: (data) => {
        data.unshift({
          id: undefined,
          name: '全部',
          value: undefined,
        });
        return data;
      },
    });
    this.bindGet(getBannedTime, 'timeList', {
      sendingData: {},

    });

    this.getAll();
  },
};
</script>

<style lang="scss" scoped>
  .with-pre-select {
    .el-input-group__prepend {
      .el-select {
        width: 160px;
      }
    }
  }

  .money-range {
    .el-input {
      width: 100px;
    }
  }

</style>
